﻿@model IEnumerable<RepertorySystem.Models.StorageList>
@Scripts.Render("~/bundles/jquery")
@{
    ViewBag.Title = "Index";
}
@{
    //获取端口
    IServiceProvider provider = (IServiceProvider)HttpContext.Current;
    HttpWorkerRequest request = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
    var port = HttpContext.Current.Request.Url.Port;

}
<h2>库存详情 <span class="glyphicon glyphicon-inbox" style="color: rgb(200, 153, 107);"></span></h2>

<div class="col-lg-3 divfloat">
    <div class="input-group">
        <input id="searchInput" type="text" class="form-control" placeholder="输入书名" />
        <span class="input-group-btn">
            <input id="searchButton" class="btn btn-default" type="button" value="搜索" />
        </span>
    </div><!-- /input-group -->
</div>
<div id="a_Div"></div>
<script type="text/javascript">
    $("#searchButton").click(function(){
        var searchContent = $("#searchInput").val();

        if(searchContent == "" ){
            alert("请输入搜索内容");
        }else{
            window.location.href ="http://localhost:"+@port+"/StorageLists/FindOne?book_Name="+searchContent;
        }
    });

</script>

@*<p>
    @Html.ActionLink("Create New", "Create")
</p>*@
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Book_Id)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Book_Number)
        </th>
        <th></th>
    </tr>
@if (ViewBag.content == null) {
    <tr>未查找到内容！</tr>
} else {
    foreach (var item in ViewBag.content) {
    <tr>
        <td class="@item.Book_Id">
            
            @if (@item.Book_Id != null) {
                <script type="text/javascript">
                        var bookId = @item.Book_Id;
                        $.ajax({
                            url: "http://localhost:"+@port+"/api/Books/"+bookId,
                            type:"get",
                            success: function (result) {
                                $(".@item.Book_Id").text(result.Name);
                            },
                            error: function (msg) {
                                console.log(msg);
                            }

                        });

                </script>
            }
        </td>
        <td>
            @item.Book_Number
        </td>
        <td>
            @*@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
            @Html.ActionLink("Details", "Details", new { id=item.ID }) |*@
            <span class="glyphicon glyphicon-trash" style="color: rgb(200, 153, 107); font-size: 15px;">
                @Html.ActionLink("删除", "Delete", new { id = item.ID })
            </span>
        </td>
    </tr>
    }
}

</table>

<div id="pagebar">
    <ul class="pagination">
        @for (var i = 0; i < ViewBag.totalPages; i++)
        {

            if (ViewBag.currentPage == (i + 1))
            {
                <li><span class="currentPage">@(i + 1)</span></li>
            }
            else
            {
                //<a class="nextOrPreviousPage" href="javascript:;">@(i + 1)</a>
                var number = i + 1;
                <li>@Html.ActionLink("" + number, "GetNext", new { currentPage = number });</li>
            }
        }
    </ul>
</div>
